<template>
  <div>
    <div class="purchase-num">
      <div>成交人数：</div>
      <span>{{ num }}</span>
    </div>
    <a-table rowKey="completeTime" :loading="tableLoading" :columns="columns" :dataSource="data" v-bind="tableConfig" size="middle">
      <div slot="money" slot-scope="text" style="color: #E03437;">
        ¥{{ text }}
      </div>
    </a-table>
    <paging
      style="margin-top: 10px;"
      :total="paging.total"
      :current="paging.page"
      :defaultPageSize="paging.limit"
      @pageChange="handlePageChange"
      ref="paging"
    />
  </div>
</template>

<script>
import {tradeList} from '@/api/goods'
import Paging from '@/components/base/Paging'
import {purchaseRecordsColumns} from '../config'
import {pageMixin, tableMixin} from '@/mixins'
import {traderStatics} from '../../../api/goods'

export default {
  name: 'PurchaseRecords',
  props: {
    id: ''
  },
  components: {
    Paging
  },
  mixins: [pageMixin, tableMixin],
  data () {
    return {
      data: [],
      num: 0,
      columns: purchaseRecordsColumns
    }
  },
  created () {
    this.loadNums()
    this.loadData()
  },
  methods: {
    loadData () {
      this.tableLoading = true
      tradeList({page: this.paging.page, limit: this.paging.limit, goodsId: this.id}).then(res => {
        this.tableLoading = false
        if (res.code === 0) {
          this.data = res.data.records
          this.paging.total = Number(res.data.total)
        }
      }).catch(e => {
        console.log(e)
        this.tableLoading = false
      })
    },
    loadNums () {
      traderStatics({}, this.id).then(res => {
        if (res.code === 0) {
          this.num = res.data || 0
        }
      })
    },
    handlePageChange (page, limit) {
      this.paging.page = page
      this.paging.limit = limit
      this.loadData()
    }
  }
}
</script>

<style scoped lang="scss">
>>>.ant-table-thead > tr > th{
  font-weight: 400!important;
}
.purchase-num {
  width: 100%;
  border-bottom: 1px dashed #c7c7c7;
  padding-bottom: 20px;
  padding-top: 4px;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC, sans-serif;
  font-weight: 400;
  color: #646464;
  line-height: 14px;
  margin-bottom: 20px;

  span {
    margin-left: 10px;
    font-size: 30px;
    font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
    font-weight: 600;
    color: #E03437;
    line-height: 30px;
  }
}
</style>
